/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bllImplement;

import bllInterface.Account;
import bllInterface.BLLAccount;
import bllobject.AccountImpl;
import dalfactory.SDALFactory;
import java.rmi.RemoteException;
import utils.*;

/**
 *
 * @author salm
 */
public class BLLAccountImpl implements BLLAccount
{
    @Override
    public Account getAccount(String userName, String password) throws RemoteException
    {
        // NEED TABLE
        DataTable dt = SDALFactory.getInstance().getAccount().getAccount(userName, password);
        if (dt.size() > 0)
        {
            DataRow row = dt.get(0);
            return AccountImpl.createRemoteAccount(row.get("UserID"), row.get("UserName"), Integer.parseInt(row.get("Experience")), Integer.parseInt(row.get("Level")), row.get("TypeID"));
        }
        
        return null;
    }

    @Override
    public boolean isAccountExist(String userName) throws RemoteException
    {
        return SDALFactory.getInstance().getAccount().isAccountExist(userName);
    }

    @Override
    public boolean changePassword(String userName, String oldPas, String newPas) throws RemoteException
    {
        return SDALFactory.getInstance().getAccount().changePassword(userName, oldPas, newPas);
    }
    
    @Override
    public Account register(String userName, String password) throws RemoteException
    {
        if (SDALFactory.getInstance().getAccount().insertAccount(userName, password))
        {
            return getAccount(userName, password);
        }
        
        return null;
    }
}
